(function () {
    var _BookStore = function (opts) {
    };

    /*
     * 判断是否是高清屏
     * 如果是高清屏,需要处理1像素的问题
     * 只判断苹果设备,安卓设备玩去0.0
     * */
    function initRetina() {
        var isIphone = window.navigator.appVersion.match(/iphone/ig);
        var devicePixelRatio = window.devicePixelRatio || 1;
        if (devicePixelRatio >= 2) {
            var $div = $('<div style="border: .5px solid transparent;"></div>'),
                $html = $('html');
            $('body').append($div);
            isIphone && $html.addClass("dpr-" + devicePixelRatio);
            if ($div[0].offsetHeight == 1) {
                $html.addClass("hair-lines");
            }
            $div.remove();
        }
    }
    /*
     * 构造函数原型
     * */
    _BookStore.prototype = {
        constructor: _BookStore,
        init: function (opts) {
            this.options = opts;
            this.render();
            this.events();
            this.plugins();
        },
        render: function () {

        },
        events: function () {
            $('#wrapSlider').slider({
                type: 1
            });
            $('#moduleIndex>.group-btn>.btn-primary').click(function(){
                // window.location.href="/eBook/book/detail";
                window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx08379b83fa805962&redirect_uri=http%3A%2F%2F40lsgy1.tunnel.qydev.com%2FeBook%2Fbook%2Fdetail&response_type=code&scope=snsapi_base&state=state#wechat_redirect";
            });
            $('#moduleDetails>.group-btn>.btn-primary').click(function(){
                $.ajax({
                    url: "/eBook/prepayId/generate",
                    data: {
                        "bookId": 1,
                        "price": 1,
                        "userId": $("#userId").val()
                    },
                    success: function(response) {
                        if (typeof WeixinJSBridge == "undefined"){
                            if( document.addEventListener ) {
                                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                            } else if (document.attachEvent) {
                                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                            }
                        } else {
                            WeixinJSBridge.invoke(
                                'getBrandWCPayRequest',
                                response.errorBody,
                                function(res){
                                    if(res.err_msg == "get_brand_wcpay_request：ok" ) {}
                                }
                            );
                        }
                    }
                })
            });
        },
        plugins: function () {
            initRetina();
        }
    };

    //挂载全局变量
    window.BookStore = _BookStore;
})();

$(function () {
    var bookStore = new BookStore();
    bookStore.init();
});